package com.akupilih.app;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class BeritaDetailActivity extends BaseActivity {
	TextView title, author, date, content;
	String url = "";
	String titleBerita = "";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_detail_berita);
		getSupportActionBar().setTitle("Berita");
		title = (TextView) findViewById(R.id.c_title);
		author = (TextView) findViewById(R.id.c_author);
		date = (TextView) findViewById(R.id.c_date);
		content = (TextView) findViewById(R.id.c_excerpt);

		ArrayList<HashMap<String, String>> data = (ArrayList<HashMap<String, String>>) getIntent()
				.getSerializableExtra("berita");
		for (int i = 0; i < data.size(); i++) {
			title.setText(data.get(i).get("title").toString());
			author.setText(data.get(i).get("author").toString());
			date.setText(data.get(i).get("date").toString());
			content.setText(Html
					.fromHtml(data.get(i).get("content").toString()));
			url = data.get(i).get("url").toString();
			titleBerita = data.get(i).get("title").toString();
		}

	}

	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.share, menu);
        return true;
    }
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		if (item.getItemId() == android.R.id.home) {
			finish();
		}else if(item.getItemId() == R.id.share){
			Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, url+" (via @akupilihapp)");
            intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Check out this site!");
            startActivity(Intent.createChooser(intent, "Share"));
		}
		return true;
	}
}
